﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;

namespace PBTService
{
    

    [ServiceContract(CallbackContract=typeof(IPaintballCallbackClient))]
    public interface IPaintballServer
    {
        /// <summary>
        /// Starts the Server with a specified host
        /// </summary>
        /// <param name="host"></param>
        [OperationContract(IsOneWay=true)]
        void StartupServer(PBTGamePlayer host);

        /// <summary>
        /// Registers a client as a game player
        /// </summary>
        /// <param name="client"></param>
        [OperationContract(IsOneWay = true)]
        void Register(PBTGamePlayer client);


        [OperationContract(IsOneWay = true)]
        void Send(PBTServiceMessage message);
    }

    public interface IPaintballCallbackClient
    {
        [OperationContract]
        void MessageReceived(PBTServiceMessage message);
    }

    [DataContract]
    public class PBTGamePlayer
    {
        public string Username { get; private set; }

        public PBTGamePlayer(string username)
        {
            this.Username = username;

        }
    }

    [DataContract]
    [KnownType(typeof(PBTChatMessage))]
    [KnownType(typeof(PBTUpdateMessage))]
    [KnownType(typeof(PBTActionMessage))]
    public class PBTServiceMessage
    {
        [DataMember]
        public PBTGamePlayer Sender { get; private set; }

        [DataMember]
        public DateTime Timestamp { get; private set; }

        [DataMember]
        public object Tag { get; set; }

        //cTor
        public PBTServiceMessage(PBTGamePlayer sender)
        {
            this.Sender = sender;
            this.Timestamp = DateTime.Now;
        }
    }
}
